package testCasalib 
{
	import flash.events.IOErrorEvent;
	import org.casalib.display.CasaMovieClip;
	import org.casalib.events.LoadEvent;
	import org.casalib.load.GroupLoad;
	import org.casalib.load.ImageLoad;
	
	/**
	 * ...
	 * @author ...
	 */
	public class groupload extends CasaMovieClip 
	{
        protected var _groupLoad:GroupLoad;
        protected var _imageOne:ImageLoad;
        protected var _imageTwo:ImageLoad;
        protected var _imageThree:ImageLoad;
        protected var _imageFour:ImageLoad;

		public function groupload() 
		{
			super();

            this._imageOne   = new ImageLoad("assets/1.jpg");
            this._imageTwo   = new ImageLoad("assets/2.jpg");
            this._imageThree = new ImageLoad("assets/3.jpg");
            this._imageFour  = new ImageLoad("assets/4.jpg");

            this._imageTwo.loader.x   = 10;
            this._imageThree.loader.x = 20;
            this._imageFour.loader.x  = 30;

            this.addChild(this._imageOne.loader);
            this.addChild(this._imageTwo.loader);
            this.addChild(this._imageThree.loader);
            this.addChild(this._imageFour.loader);

            this._groupLoad = new GroupLoad();
            this._groupLoad.addLoad(this._imageOne);
            this._groupLoad.addLoad(this._imageTwo);
            this._groupLoad.addLoad(this._imageThree);
            this._groupLoad.addLoad(this._imageFour);
            this._groupLoad.addEventListener(IOErrorEvent.IO_ERROR, this._onError);
            this._groupLoad.addEventListener(LoadEvent.PROGRESS, this._onProgress);
            this._groupLoad.addEventListener(LoadEvent.COMPLETE, this._onComplete);
            this._groupLoad.start();

		}
		protected function _onError(e:IOErrorEvent):void {
            trace("There was an error");
            this._groupLoad.removeLoad(this._groupLoad.erroredLoads[0]);
        }

        protected function _onProgress(e:LoadEvent):void {
            trace("Group is " + e.progress.percentage + "% loaded at " + e.Bps + "Bps.");
        }

        protected function _onComplete(e:LoadEvent):void {
            trace("Group has loaded.");
        }

	}

}